//
//  FormViewController.m
//  TYUIKit_Example
//
//  Created by 谢航宇 on 2023/3/20.
//  Copyright © 2023 谢航宇. All rights reserved.
//

#import "FormViewController.h"
#import "TYFormView.h"
#import "Masonry.h"
@interface FormViewController ()
@property (retain, nonatomic) TYFormView *formView;
@property (retain, nonatomic) TYFormData * formData;
@end

@implementation FormViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.formView refresh];
}

- (TYFormView *)formView {
    if (!_formView) {
        _formView = [[TYFormView alloc]initWithFormData:self.formData];
        [self.view addSubview:_formView];
        [_formView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.top.mas_equalTo(self.view);
        }];
    }
    return _formView;
}


- (TYFormData *)formData {
    if (!_formData) {
        _formData = [[TYFormData alloc]initWithItemArray:[[NSMutableArray alloc]init]];
        [_formData.itemArray addObject:[self getItemWithType:(TYFormItemTypeText) title:@"姓名" placeholder:@"请输入姓名" value:nil key:@"name"]];
        
        [_formData.itemArray addObject:[self getItemWithType:(TYFormItemTypeArrow) title:@"性别" placeholder:@"请选择性别" value:nil key:@"sex"]];
        
        [_formData.itemArray addObject:[self getItemWithType:(TYFormItemTypeArrow) title:@"证件类型" placeholder:@"请选择证件类型" value:nil key:@"idType"]];
        
        [_formData.itemArray addObject:[self getItemWithType:(TYFormItemTypeText) title:@"证件号码" placeholder:@"请输入证件号码" value:nil key:@"identity_id"]];
        
        [_formData.itemArray addObject:[self getItemWithType:(TYFormItemTypeText) title:@"户籍地址" placeholder:@"请选择户籍地址" value:nil key:@"hjdz"]];
        
        [_formData.itemArray addObject:[self getItemWithType:(TYFormItemTypeText) title:@"现住址" placeholder:@"请选择现住址" value:nil key:@"addr"]];
    }
    return _formData;
}


- (TYFormItem *)getItemWithType:(TYFormItemType)type title:(NSString *)title placeholder:(NSString *)placeholder value:(NSString *)value key:(NSString *)key {
    TYFormItem * formItem = [[TYFormItem alloc]initWithType:type];
    formItem.type = type;
    formItem.title = title;
    formItem.placeholder = placeholder;
    formItem.oldValue = value;
    formItem.key = key;
    return formItem;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
